package com.hw.protocol.tool.decode.hb;

import com.hw.protocol.tool.model.entity.hb.RegulatorBox;
import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;

/**
 * @author : lihy
 * @date : 2023/11/3 10:23
 * description: 调压箱实时数据解码器
 */
public class RegulatorBoxDecode {

    private ByteBuf dataBuf;

    private RegulatorBox box;

    public RegulatorBoxDecode(String devSerial, byte[] data) {
        this.dataBuf = Unpooled.wrappedBuffer(data);
        box = new RegulatorBox();
        box.setDevSerial(devSerial);
    }

    public RegulatorBox buildObject(){
        box.setTime(DecodeUtil.getTime(dataBuf));
        box.setInPress(dataBuf.readFloatLE());
        box.setOutPress(dataBuf.readFloatLE());
        box.setTemperature(dataBuf.readFloatLE());
        box.setDifferentialPressure1(dataBuf.readFloatLE());
        box.setDifferentialPressure2(dataBuf.readFloatLE());
        box.setLeakage(dataBuf.readFloatLE());
        box.setValveOpening1(dataBuf.readByte());
        box.setValveOpening2(dataBuf.readByte());
        box.setValveSsv1(dataBuf.readByte());
        box.setValveSsv2(dataBuf.readByte());
        box.setDoorSignal1(dataBuf.readByte());
        box.setDoorSignal2(dataBuf.readByte());

        //跳过预留字段
        dataBuf.skipBytes(12);

        box.setSignal(dataBuf.readByte());
        box.setUploadType(dataBuf.readByte());

        dataBuf.release();
        return box;
    }
}
